package org.ckhd.calculate24;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 启动“算24点”游戏
 */
public class StartGame {

    public static void main(String[] args) {
        int target = 24;
        Scanner sc = new Scanner(System.in);
        System.out.println("欢迎进入“算24点”游戏！");

        System.out.print("请输入目标数，默认为24，按回车跳过：");
        String inputTarget = sc.nextLine().replaceAll(" ", "");
        if (inputTarget.matches("[0-9]+")) {
            target = Integer.valueOf(inputTarget);
        }
        System.out.println("游戏开始，目标结果为：" + target);

        System.out.println("-------------------------------------");
        while (true) {
            System.out.print("请输入2-6个正整数，用空格隔开：");
            String inputNum = sc.nextLine();
            String[] arr = inputNum.split(" ");
            List<Integer> numList = new ArrayList<>();
            for (String str : arr) {
                if (!"".equals(str.trim())) {
                    numList.add(Integer.valueOf(str.trim()));
                }
            }
            // 调用方法，执行“算24点”
            Calculate24.printResult(numList, target);
            System.out.println("-------------------------------------");
            System.out.print("游戏自动继续，");
        }
    }

}
